package stockblaster.client.facilities;

import java.util.ArrayList;
import java.util.HashMap;

import stockblaster.client.CurrentUser;

public class Facilities {
	//facilities constants
	public final static int FACILITY_DEBT = 1;
	public final static int FACILITY_IMPROVED_FOOD = 2;
	public final static int FACILITY_RENOVATED_ROOMS = 3;
	public final static int FACILITY_IMPROVED_STAFF = 4;
	public final static int FACILITY_BALLROOM = 5;
	public final static int FACILITY_SWIMMING_POOL = 6;
	public final static int FACILITY_SPA_GYM = 7;
	
	//income gained per month based on facilities owned
	public final static double INCOME_PAY_OFF_DEBT = 250.00;
	public final static double INCOME_IMPROVED_FOOD = 500.00;
	public final static double INCOME_RENOVATED_ROOMS = 1000.00;
	public final static double INCOME_IMPROVED_STAFF = 1150.00;
	public final static double INCOME_BALLROOM = 1500.00;
	public final static double INCOME_SWIMMING_POOL_SUMMER = 2500.00;
	public final static double INCOME_SWIMMING_POOL = 1250.00;
	public final static double INCOME_SPA_GYM = 2700.00;
	
	//mapping of the income from facilities
	private static HashMap<Integer, Double> income = new HashMap<Integer, Double>();
	
	//storage for facilities owned
	private static ArrayList<Integer> facilities = new ArrayList<Integer>();
	
	public static void init() {
		income.put(FACILITY_DEBT, INCOME_PAY_OFF_DEBT);
		income.put(FACILITY_IMPROVED_FOOD, INCOME_IMPROVED_FOOD);
		income.put(FACILITY_RENOVATED_ROOMS, INCOME_RENOVATED_ROOMS);
		income.put(FACILITY_IMPROVED_STAFF, INCOME_IMPROVED_STAFF);
		income.put(FACILITY_BALLROOM, INCOME_BALLROOM);
		income.put(FACILITY_SWIMMING_POOL, INCOME_SWIMMING_POOL);
		income.put(FACILITY_SPA_GYM, INCOME_SPA_GYM);
	}
	
	public static ArrayList<Integer> getFacilities() {
		return facilities;
	}
	
	public static int getFacilitiesCount() {
		return facilities.size();
	}
	
	public static void addFacility(Integer facility) {
		facilities.add(facility);
	}
	
	/**
	 * Method to add the monthly income to user's assets
	 */
	public static void addMonthlyIncome() {
//		int size = facilities.size();
//		Integer inc = 0;
//		if (size > 0) {
//			for (int i = 0; i < size; ++i) {
//				inc = facilities.get(i);
//				if (inc != null)
//					CurrentUser.addFund(income.get(inc));
//			}
//		}
		CurrentUser.addFund(getTotalMonthlyIncome());
	}
	
	public static Double getTotalMonthlyIncome() {
		int size = facilities.size();
		Integer inc = 0;
		Double result = 0.00;
		if (size > 0) {
			for (int i = 0; i < size; ++i) {
				inc = facilities.get(i);
				if (inc != null)
					result += income.get(inc);
			}
		}
		return result;
	}
}
